package com.flx.ark.spring.code.user.config;

import com.flx.ark.spring.code.user.controller.UserController;
import com.flx.ark.spring.code.user.property.UserProperties;
import com.flx.ark.spring.code.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: Fenglixiong
 * @Date: 2021/9/3 14:43
 * @Description:
 */
@Slf4j
@Configuration
@ConditionalOnWebApplication
@ConditionalOnBean(ConfigMarker.class) //当ConfigMarker存在的时候才会初始化这个配置类
@EnableConfigurationProperties(value = UserProperties.class)
public class UserAutoConfiguration {

    static {
        log.info("====>UserAutoConfiguration init...");
    }

    @Bean
    @ConditionalOnMissingBean
    public UserService userService(){
        return new UserService();
    }

    @Bean
    @ConditionalOnBean(UserService.class)
    public UserController userController(){
        return new UserController();
    }

}
